import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/couser_center/textbook_list_entity.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

class OnlineIngCourseController extends GetxController {
  GlobalKey<ScaffoldState> riskRightScaffoldKey = GlobalKey<ScaffoldState>();
  GlobalKey<CustomEasyRefreshListState> globalKey = GlobalKey();
  RxString searchX = ''.obs;

/// 获取数据 查询改计划下的课程列表
  Future<List<TextbookListEntity>> textbookList(int index, int size, {String? search}) async {
    final res = await HttpUtil().generateGetRequest<List<TextbookListEntity>>(
      Interface.getTextBookByPlanId,
      queryParameters: {
        'pageNum': index,
        'pageSize': size,
        'id': Get.arguments, //外面的列表id
        'bookName': searchX, //模糊查询 课程名字
      },
    ).execute();
    List<TextbookListEntity>? list = [];
    res.onSuccess((result) {
      if (result.data != null) {
        list = result.data;
      }
    });
    return list!;
  }

  ///点击进入课程详情
  void courseDetail(TextbookListEntity item) {
    //条目课程id  讲师id（需要 查询讲师详情/education//lecturer/detail）
    Get.toNamed(AppRoutes.courseDetailPage, arguments: {
      'id': item.textbookId,
      'textbookLecturerId': item.textbookLecturerId ?? '',
      //isDirectory && isQuestion 都为0时（不进入学习 false）
      'isStudy': item.isDirectory == 0  ? false : true,
    });
  }
}
